package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.DBDao;

public class Province extends HttpServlet {

	private static final long serialVersionUID = 1L;

	private DBDao dbDao = new DBDao();
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		String sql = "select provinceID, province from hat_province";
		ResultSet rs = dbDao.excuteSelect(sql);
		StringBuffer rst1 = new StringBuffer();
		String rst2 = new String();
		try {
			while(rs.next()) {
				rst1.append(";" + rs.getString("provinceID") + "," + rs.getString("province"));
			}
			rst2 = rst1.substring(1);
			out.println(rst2);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			dbDao.close(rs);
		}
		out.flush();
		out.close();
	}

}
